package com.hqyj.utile;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

@Component
public class EmailUtile {

    //邮件发送的类
    @Autowired
    private JavaMailSender javaMailSender;
    /**
     *
     * @param email 收件人
     * @param content 邮件正文
     * @param subject  邮件标题
     * @return true 发送成功 ,false代表发送失败
     */
    public  boolean sead(String email,String content,String subject){

        try{
            SimpleMailMessage message = new SimpleMailMessage();
            //设置发件人
            message.setFrom("2695070944@qq.com");
            //设置收件人
            message.setTo(email);
            //设置 邮件正文
            message.setText(content);
            //设置邮件标题
            message.setSubject(subject);
            //发送
            javaMailSender.send(message);
            return true;
        }catch (Exception e){
            e.printStackTrace();
        }

        return false;

    }

}
